{% extends 'registrar/base.html' %}
{% load staticfiles %}
{% block content %}
        <!-- Page Heading -->
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    Courses
                    <small>The following are the available courses on Academics Today</small>
                </h1>
                <ol class="breadcrumb">
                    <li class="active">
                        <i class="fa fa-university"></i> Courses
                    </li>
                </ol>
            </div>
        </div>
        <!-- /.row -->

        {% if courses.object_list.count == 0 %}
        <div class="jumbotron">
            <h1>Courses Unavailable</h1>
            <p>Please check back at a later time when the course become available.</p>
        </div>
        {% else %}
        <!-- Course Rows -->
        {% for course in courses %}
            {% include 'registrar/courses/course_row.html' %}
        {% endfor %}
        <!-- /.Course Rows -->
        <!-- Pagination -->
        <div class="panel-body text-right">
            <div class="pagination">
                <span class="step-links">
                    <span class="current">
                        Page {{ courses.number }} of {{ courses.paginator.num_pages }}.
                    </span>
                    
                    {% if courses.has_previous %}
                    <a href="?page={{ courses.previous_page_number }}"
                        type="button"
                        class="btn btn-lg btn-primary">Previous</a>
                    {% endif %}
                    
                    {% if courses.has_next %}
                    <a href="?page={{ courses.next_page_number }}"
                        type="button"
                        class="btn btn-lg btn-primary">Next</a>
                    {% endif %}
                </span>
            </div>
        </div>
        <!-- /.row -->
        
        {% endif %}
</div>
<script>
    /**
     *  Function will call AJAX function to enroll into a specific course for the
     *  current logged on user.
     */
    function ajax_enroll(course_id)
    {
        var url = 'enroll';

        $.ajax( url, {
           data: {
               'course_id' : course_id,
               'csrfmiddlewaretoken': '{{ csrf_token }}',
           },
           type: 'post',
           success: function(result) {
               // success code execution here
               if (result.status == 'success')
               {
                   window.location = 'course/' + course_id + '/announcements';
               }
           },
           error: function(xhr,status,error) {
               // error code here
           },
           complete: function(xhr,status) {
               // completion code here
           }
        });
    }
</script>
{% endblock content %}
